package test;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.jupiter.api.Test;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 描述: TODO
 * 作者: yanruizhi
 * 时间: 2023/11/17 10:36
 */
@Component
public class RomaNum {
    @Test
    public void main() {
        int vi = romanToInt("MCMXCIV");
        System.out.println(vi);

    }

    public int romanToInt(String s) {
        List<num> nums = new ArrayList<>();
        nums.add(new num("I", 1, 0));
        nums.add(new num("V", 5, 1));
        nums.add(new num("X", 10, 2));
        nums.add(new num("L", 50, 3));
        nums.add(new num("C", 100, 4));
        nums.add(new num("D", 500, 5));
        nums.add(new num("M", 1000, 6));
         HashMap<String, num> map = new HashMap<>();
         for (int i = 0; i < nums.size(); i++) {
             map.put(nums.get(i).getRomanNum(), nums.get(i));
         }

        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < nums.size(); j++) {
                if (nums.get(j).getRomanNum().equals(s.substring(i, i + 1))) {
                    sum += nums.get(j).getValue();
                    break;
                }
            }
        }
        for (int i = 0; i < s.length()-1; i++) {
            num preNum = map.get(String.valueOf(s.charAt(i)));
            num sufNum = map.get(String.valueOf(s.charAt(i+1)));
            if (preNum.getIndex() < sufNum.getIndex()) {
                sum -= 2*preNum.getValue();
            }
        }
        return sum;
    }

    class num {
        private String romanNum;
        private int value;
        private int index;

        public num(String romanNum, int value, int index) {
            this.romanNum = romanNum;
            this.value = value;
            this.index = index;
        }

        public String getRomanNum() {
            return romanNum;
        }


        public int getValue() {
            return value;
        }


        public int getIndex() {
            return index;
        }

    }


    @Test
    public void leetCode15() {
        int[] nums = new int[]{-1,0,1,2,-1,-4,-2,-3,3,0,4};
        List<List<Integer>> res = new ArrayList<>();
        List<List<Integer>> result = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                for (int k = 0; k < nums.length; k++) {
                    if (i != j && i != k && j != k && nums[i] + nums[j] + nums[k] == 0) {
                        ArrayList<Integer> list = new ArrayList<>();
                        list.add(nums[i]);
                        list.add(nums[j]);
                        list.add(nums[k]);
                        res.add(list);
                    }
                }
            }
        }
        for (List<Integer> re : res) {
            System.out.println(re);
        }

        Set modle = new HashSet();
        for (List<Integer> list : res) {
            //求list模长
            int mo = 0;
            for (Integer i : list) {
                mo += i * i;
            }
            if (!modle.contains(mo)) {
                modle.add(mo);
                result.add(list);
            }
        }

        System.out.println(result);

    }
}
